package com.colortea.action.frontstage.order;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.colortea.action.backstage.base.BaseTAction;
import com.colortea.action.backstage.base.DataCollectionTAction;
import com.colortea.action.backstage.utils.statickey.StaticKey;
import com.colortea.entity.MemberT;
import com.colortea.entity.ShippingAddressT;
import com.colortea.service.OrderBaseProcessTService;
import com.colortea.service.impl.Serial;
import com.opensymphony.xwork2.ActionContext;

@ParentPackage("colortea")
@Namespace("/order")
@InterceptorRefs({ @InterceptorRef("defaultStack") })
public class FrontPayOrderAction extends BaseTAction {
	@Resource
	private DataCollectionTAction dataCollectionTAction;
	@Resource
	private OrderBaseProcessTService orderBaseProcessTService;

	@Action(value = "payOrder", results = { @Result(name = "json", type = "json") })
	public String payOrder() {
		this.dataCollectionTAction.putBaseInfoToContext();
		MemberT membert = (MemberT) ActionContext.getContext().getSession()
				.get(StaticKey.MEMBER_SESSION_KEY);
		if (membert != null) {
			if (StringUtils.isNotBlank(this.getDeliveraddressid())
					&& StringUtils.isNotBlank(this.getPaymentid())
					&& StringUtils.isNotBlank(this.getCartgoodsid())
					&& StringUtils.isNotBlank(this.getFreight())
					&& StringUtils.isNotBlank(this.getIsgoodsfromcart())
					&& StringUtils.isNotBlank(this.getOrdertag())
					&& StringUtils.isNotBlank(this.getInvoiceid())) {
				orderObj = this.orderBaseProcessTService.saveFrontOrder(
						deliveraddressid, paymentid, cartgoodsid, logisticsid,
						freight, customernotes, isgoodsfromcart, ordertag,
						invoiceid, membert, defaultbank);
				if (orderObj != null) {
					// 跳转支付页面
				}
			}
		}
		return JSON;
	}

	private String orderid;
	/**
	 * 用户选择的收获地址id
	 */
	private String deliveraddressid;
	/**
	 * 用户选择的支付方式id
	 */
	private String paymentid;
	/**
	 * 页面上传递过来的购物车商品id，如果直接购买则是商品id
	 */
	private String cartgoodsid;
	/**
	 * 货物是否从购物车取出并计算标记
	 */
	private String isgoodsfromcart;
	/**
	 * 物流商id
	 */
	private String logisticsid;
	/**
	 * 运费
	 */
	private String freight;
	/**
	 * 订单备注
	 */
	private String customernotes;
	/**
	 * 订单标记
	 */
	private String ordertag;
	/**
	 * 我的开票信息id
	 */
	private String invoiceid;
	
	/**
	 * 支付信息
	 */
	private OrderObj orderObj;

	/**
	 * 银行简码
	 */
	private String defaultbank;
	
	public String getInvoiceid() {
		return invoiceid;
	}

	public void setInvoiceid(String invoiceid) {
		this.invoiceid = invoiceid;
	}

	public String getOrdertag() {
		return ordertag;
	}

	public void setOrdertag(String ordertag) {
		this.ordertag = ordertag;
	}

	public String getIsgoodsfromcart() {
		return isgoodsfromcart;
	}

	public void setIsgoodsfromcart(String isgoodsfromcart) {
		this.isgoodsfromcart = isgoodsfromcart;
	}

	public String getCustomernotes() {
		return customernotes;
	}

	public void setCustomernotes(String customernotes) {
		this.customernotes = customernotes;
	}

	public String getFreight() {
		return freight;
	}

	public void setFreight(String freight) {
		this.freight = freight;
	}

	public String getLogisticsid() {
		return logisticsid;
	}

	public void setLogisticsid(String logisticsid) {
		this.logisticsid = logisticsid;
	}

	public String getCartgoodsid() {
		return cartgoodsid;
	}

	public void setCartgoodsid(String cartgoodsid) {
		this.cartgoodsid = cartgoodsid;
	}

	public String getPaymentid() {
		return paymentid;
	}

	public void setPaymentid(String paymentid) {
		this.paymentid = paymentid;
	}

	public String getDeliveraddressid() {
		return deliveraddressid;
	}

	public void setDeliveraddressid(String deliveraddressid) {
		this.deliveraddressid = deliveraddressid;
	}

	public String getOrderid() {
		return orderid;
	}

	public void setOrderid(String orderid) {
		this.orderid = orderid;
	}

	public OrderObj getOrderObj() {
		return orderObj;
	}

	public void setOrderObj(OrderObj orderObj) {
		this.orderObj = orderObj;
	}

	public String getDefaultbank() {
		return defaultbank;
	}

	public void setDefaultbank(String defaultbank) {
		this.defaultbank = defaultbank;
	}

}
